package sat.component;

import java.io.File;

import org.mt4j.MTApplication;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.shapes.MTRoundRectangle;
import org.mt4j.components.visibleComponents.widgets.MTTextField;
import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragEvent;
import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragProcessor;
import org.mt4j.input.inputProcessors.componentProcessors.rotateProcessor.RotateProcessor;
import org.mt4j.input.inputProcessors.componentProcessors.scaleProcessor.ScaleProcessor;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;

//import apple.laf.JRSUIConstants.Direction;

import processing.core.PImage;

public class DragAndDropButton extends MTRoundRectangle{

	public static final float cornerRadius = 20;
	private static final float commentWidth = 100;
	private static final float commentHeight = 30;
	//	private static final float commentArcRadius = 30;

	public enum ButtonType{SAVE,CLEAR,SAVEANDQUIT,QUIT,LINK};

	private ButtonType m_type;

	public  MTTextField comment = null;

	public void showComment(){
		comment.setVisible(true);
	}

	public void hideComment(){
		comment.setVisible(false);
	}

	public DragAndDropButton(MTApplication mtApplication,final ButtonType buttonType, String iconName) {
		super(mtApplication, 0, 0, 0, cornerRadius*2, cornerRadius*2, cornerRadius, cornerRadius);


		m_type = buttonType;

		comment = new MTTextField(mtApplication, 0, 0, commentWidth, commentHeight, 
				FontManager.getInstance().createFont(mtApplication, "arial.ttf",
						10, // Font size
						MTColor.BLACK, // Font fill color
						true));
		switch (m_type){
		case SAVE: 
			comment.setText("SAVE");
			comment.setPositionRelativeToParent(new Vector3D(-cornerRadius/2+15,-cornerRadius/2));
			break;
		case CLEAR: 
			comment.setText("CLEAR ALL");
			comment.setPositionRelativeToParent(new Vector3D(cornerRadius/2+60,-cornerRadius/2));
			break;
		case SAVEANDQUIT: 
			comment.setText("SAVE AND QUIT");
			comment.setPositionRelativeToParent(new Vector3D(-cornerRadius/2-40,cornerRadius/2+35));
			break;
		case QUIT: 
			comment.setText("QUIT");
			comment.setPositionRelativeToParent(new Vector3D(cornerRadius/2+80,cornerRadius/2+40));
			break;
		default:
			break;
		}


		this.addChild(comment);
		comment.removeAllGestureEventListeners();
		comment.setNoFill(true);
		comment.setNoStroke(true);
		comment.setVisible(false);

		//		this.addChild(comment);
		String imagePath = System.getProperty("user.dir") + File.separator + "icons" + File.separator;
		PImage p = mtApplication.loadImage(imagePath + iconName);
		this.setTexture(p);

		this.setFillColor(MTColor.WHITE);
		//this.setStrokeColor(MTColor.BLACK);
		//this.setStrokeWeight(1);
		this.setNoStroke(true);

		this.removeAllGestureEventListeners(RotateProcessor.class);
		this.removeAllGestureEventListeners(ScaleProcessor.class);
		this.addGestureListener(DragProcessor.class,
				new IGestureEventListener() {
			public boolean processGestureEvent(MTGestureEvent evt) {
				DragEvent de = (DragEvent) evt;

				switch (de.getId()) {
				case MTGestureEvent.GESTURE_STARTED:
					showComment();
					break;
				case MTGestureEvent.GESTURE_ENDED:
					hideComment();
					break;
				default:
					break;
				}
				return false;
			}
		});	
	}
	// TODO 
}
